package org.example;

/**
 * @AUTHOR 尹书岿
 * @DATE 2024/12/9 13:02
 * @DESCRIBE 求PI
 */
public class Circle {
    Point heart;
    double Radius;
    public Circle(Point heart, double Radius) {
        this.heart = heart;
        this.Radius = Radius;
    }

    public boolean isPointIncircle(Point point) {
        double distance = this.heart.getDistance(point);
        return distance <= this.Radius;
    }

    public static void main(String[] args) {
        Point heart = new Point(1, 1);
        Circle circle = new Circle(heart,1);
        int total = 0;
        for(int i = 0; i< 100000; i++) {
            double x = Math.random()*2;
            double y = Math.random()*2;
            Point tmppoint = new Point(x, y);
            if (circle.isPointIncircle(tmppoint)) {
                total++;
            }
        }
        System.out.println(total * 4.0 / 100000);
    }


}
